<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>日记信息</title>
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>

<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>人员档案<small>日记信息</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>人员档案</el-breadcrumb-item>
            <el-breadcrumb-item>日记信息</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <div class="app-container">

        <div class="box">

            <div class="filter-container">
                <el-input placeholder="创建日期" v-model="pagination.createDate" type="date" style="width: 200px;" class="filter-item"></el-input>
                <el-input placeholder="标题" v-model="pagination.title" style="width: 200px;" class="filter-item"></el-input>
                <el-input placeholder="标签" v-model="pagination.tags" style="width: 200px;" class="filter-item"></el-input>
               <!-- <el-input placeholder="心情" v-model="pagination.mood" style="width: 50px;" class="filter-item hide-input"></el-input>-->
                <el-input placeholder="心情" v-model="pagination.mood" style="width: 200px;" class="filter-item "></el-input>
               <!-- <el-input placeholder="内容" v-model="pagination.content" style="width: 50px;" class="filter-item "></el-input>-->

                <el-button  type="success" @click="getAll()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>

            </div>

            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <!-- 页面表单 -->
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="createDate" label="创建日期"  align="center" width="100"></el-table-column>
                <el-table-column prop="title" label="标题" align="center" width="100" ></el-table-column>
                <el-table-column prop="tags" label="标签" align="center" width="100"></el-table-column>
                <el-table-column prop="mood" label="心情"  align="center" width="100"></el-table-column>
                <el-table-column prop="content" label="内容" align="center" width="500"></el-table-column>
                <el-table-column prop="majorEvent" label="大事件" align="center" width="300"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <!--分页组件-->
            <div class="pagination-container">

                <el-pagination class="pagiantion" @current-change="handleCurrentChange" :current-page="pagination.currentPage" :page-size="pagination.pageSize" layout="total, prev, pager, next, jumper" :total="pagination.total">

                </el-pagination>

            </div>

            <!-- 新增标签弹层 -->

            <div class="add-form">

                <el-dialog title="新建日记" :visible.sync="dialogFormVisible">

                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">

                        <el-row>
                              <el-col :span="12">
                                  <el-form-item label="创建日期" prop="createDate">
                                      <el-input v-model="formData.createDate" type="date"></el-input>
                                  </el-form-item>
                              </el-col>
                              <el-col :span="12">
                                <el-form-item label="标题" prop="title">
                                    <el-select v-model="formData.title">
                                        <el-option label="日常" value="日常"></el-option>
                                        <el-option label="健康" value="健康"></el-option>
                                        <el-option label="学习" value="学习"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>

                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="标签">
                                    <el-select v-model="formData.tags">
                                        <el-option label="MR" value="MR"></el-option>
                                        <el-option label="DQ" value="DQ"></el-option>
                                    </el-select>
                                </el-form-item>

                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="心情">
                                    <el-select v-model="formData.mood">
                                        <el-option label="开心" value="开心"></el-option>
                                        <el-option label="不开心" value="不开心"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="内容">
                                    <el-input v-model="formData.content" type="textarea" :rows="2"  style="width: 100%; height: 100px; font-size: 16px; padding: 10px; border-radius: 4px;" ></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="大事件">
                                    <el-input v-model="formData.majorEvent" type="textarea" :rows="2"  style="width: 100%; height: 100px; font-size: 16px; padding: 10px; border-radius: 4px;" ></el-input>
                                </el-form-item>
                            </el-col>

                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="cancel()">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑检查项" :visible.sync="dialogFormVisible4Edit">

                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="创建日期" prop="createDate">
                                    <el-input v-model="formData.createDate" type="date"  class="filter-item "></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="标题" prop="title">
                                    <el-input v-model="formData.title"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="标签">
                                    <el-input v-model="formData.tags"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="心情">
                                    <el-input v-model="formData.mood"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="内容">
                                    <el-input v-model="formData.content" type="textarea" :rows="2"  style="width: 100%; height: 100px; font-size: 16px; padding: 10px; border-radius: 4px;" ></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="大事件">
                                    <el-input v-model="formData.majorEvent" type="textarea" :rows="2"  style="width: 100%; height: 100px; font-size: 16px; padding: 10px; border-radius: 4px;" ></el-input>
                                </el-form-item>
                            </el-col>

                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="cancel()">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>

                    </div>

                </el-dialog>

            </div>

        </div>

    </div>

</div>

</body>

<!-- 引入组件库 -->

<script src="../js/vue.js"></script>

<script src="../plugins/elementui/index.js"></script>

<script type="text/javascript" src="../js/jquery.min.js"></script>

<script src="../js/axios-0.18.0.js"></script>

<script>
    var vue = new Vue({
        el: '#app',
        data: {
            dataList: [], //当前页要展示的列表数据
            dialogFormVisible: false, //添加表单是否可见
            dialogFormVisible4Edit: false, //编辑表单是否可见
            formData: {}, //表单数据
            rules: { //校验规则
                title: [{
                    required: true,
                    message: '标题为必填项',
                    trigger: 'blur'
                }]
            },
            pagination: { //分页相关模型数据
                currentPage: 1, //当前页码
                pageSize: 10, //每页显示的记录数
                total: 0, //总记录数
                createDate: "",
                title: "",
                tags: "",
                mood: "",
               // content: ""
            }
        },

        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.getAll();
            //this.findPage()

        },
        mounted() {
            this.formData.createDate = this.formatDate(new Date()); // 设置createDate的默认值为当前日期
        },


        methods: {
            //列表
            /*     getAll() {
                     //发送异步请求
                     axios.get("/books").then((res) => {
                         console.log(res.data);
                         this.dataList = res.data.data;        //列表功能
                     })
                 },*/
            //分页查询
            getAll() {
                //组织参数，拼接url请求地址
                //
                // param="?query"
                param = "?createDate=" + this.pagination.createDate;
                param += "&title=" + this.pagination.title;
                param += "&tags=" + this.pagination.tags;
                param += "&mood=" + this.pagination.mood;
               // param += "&content=" + this.pagination.content;



                //发送异步请求
                axios.get("/personalDiaries/" + this.pagination.currentPage + "/" + this.pagination.pageSize + param).then((res) => {
                    this.pagination.pageSize = res.data.data.size;
                    this.pagination.currentPage = res.data.data.current;
                    this.pagination.total = res.data.data.total;

                    this.dataList = res.data.data.records;
                    console.log(res);
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                //修改页码为当前页码值
                this.pagination.currentPage = currentPage;
                //执行查询
                this.getAll();
            },

            //弹出添加窗口
            handleCreate() {
                this.dialogFormVisible = true
                this.resetForm();
            },

            //重置表单
            resetForm() {
                this.formData = {};
            },

            //添加
            handleAdd() {
                //发送异步请求
                axios.post("/personalDiaries", this.formData).then((res) => {
                    console.log(res)
                    if (res.data.msg === 'success') { //判断当前操作是否成功
                        //1.关闭弹层
                        this.dialogFormVisible = false;
                        this.$message.success("新增成功！");
                    } else {
                        this.$message.error("新增失败！");
                    }
                }).finally(() => {
                    //2.重新加载数据
                    this.getAll();
                });
            },

            //取消
            cancel() {
                this.dialogFormVisible = false;
                this.dialogFormVisible4Edit = false;
                this.$message.success("操作取消！");
            },
            // 删除
            handleDelete(row) {

                this.$confirm("次操作永久删除，是否继续？", "提示", { //confirm  防手抖
                    type: "info"
                }).then((res) => {
                    axios.delete("/personalDiaries/" + row.id).then((res) => {
                        //console.log("success!")
                        if (res.data.msg === 'success') { //判断当前操作是否成功
                            this.$message.success("删除成功！");
                        } else {
                            this.$message.error("数据同步失败,自动刷新");
                        }
                    }).finally(() => {
                        //2.重新加载数据
                        this.getAll();
                    });
                }).catch(() => {
                    this.$message.info("取消操作");
                });
            },

            //弹出编辑窗口
            handleUpdate(row) {
                //发送异步请求
                axios.get("/personalDiaries/" + row.id).then((res) => {
                    //判断当前操作是否成功

                    if (res.data.msg === 'success' && res.data.data != null) {

                        this.dialogFormVisible4Edit = true;
                        this.formData = res.data.data;
                    } else {
                        this.$message.error("数据同步失败,自动刷新");
                    }
                }).finally(() => {
                    //2.重新加载数据
                    this.getAll();
                });
            },

            //修改
            handleEdit() {
                //发送异步请求
                axios.put("/personalDiaries", this.formData).then((res) => {
                    console.log(res.data.msg)
                    if (res.data.msg === 'success') { //判断当前操作是否成功
                        //1.关闭弹层
                        this.dialogFormVisible4Edit = false;
                        this.$message.success("修改成功！");
                    } else {
                        this.$message.error("修改失败");
                    }
                }).finally(() => {
                    //2.重新加载数据
                    this.getAll();
                });
            },
            formatDate(date) {
                const year = date.getFullYear();
                const month = (date.getMonth() + 1).toString().padStart(2, '0');
                const day = date.getDate().toString().padStart(2, '0');
                return `${year}/${month}/${day}`; // 返回格式为YYYY-MM-DD，YYYY/MM/DD的日期字符串

             },


            //条件查询
        }
    })
</script>

</html>